using System.Data;
using 图书管理系统;

namespace 图书管理系统
{
    public partial class login : Form
    {
        public login()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {
        }

        private void label2_Click(object sender, EventArgs e)
        {
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "" && textBox2.Text != "")
            {
                Login();
            }
            else
            {
                MessageBox.Show("输入有空项，请重新输入");
            }
        }
        //验证是否允许登录，允许返回真
        public void Login()
        {
            if (radioButtonUser.Checked == true)
            {
                SQLconnect sqlconnect = new SQLconnect();
                string sql = $"select * from t_user where id='{textBox1.Text}' and psw='{textBox2.Text}'";
                IDataReader dc = sqlconnect.read(sql);
                if (dc.Read())
                {
                    Data.UID = dc["id"].ToString();
                    Data.UName = dc["name"].ToString();
                    MessageBox.Show("登录成功");
                    user1 user1 = new user1();
                    this.Hide();//隐藏登录窗体
                    user1.ShowDialog();
                    this.Show();//显示登录窗体

                }
                else
                {
                    MessageBox.Show("登录失败");
                }
                //MessageBox.Show(dc[0].ToString() + dc["name"].ToString());
                sqlconnect.SQLclose();
            }
            if (radioButtonAdmin.Checked == true)
            {
                SQLconnect sqlconnect = new SQLconnect();
                string sql = $"select * from t_admin where id='{textBox1.Text}' and psw='{textBox2.Text}'";
                IDataReader dc = sqlconnect.read(sql);
                if (dc.Read())
                {
                    MessageBox.Show("登录成功");
                    admin1 admin1 = new admin1();
                    this.Hide();
                    admin1.ShowDialog();
                    this.Show();
                }
                else
                {
                    MessageBox.Show("登录失败");
                }
                sqlconnect.SQLclose();
            }
            //MessageBox.Show("请先勾选单选框");
        }
    }
}
